<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1,maximum-scale=1, user-scalable=no">
    <title>我的咨询</title>
    <%@include file="../common/rootPath.jsp" %>
    <link rel="stylesheet" type="text/css" href="${ctx}/css/reset.css"/>
    <link rel="stylesheet" href="${ctx}/css/public.css" />
    <link rel="stylesheet" type="text/css" href="${ctx}/css/body.css"/>
    <script src="http://apps.bdimg.com/libs/jquery/1.6.4/jquery.min.js"></script>
    <script type="text/javascript" src="${ctx}/js/jianrong.js"></script>
    <script type="text/javascript" src="${ctx}/js/fastclick.js"></script>
    <script type="text/javascript">
    	var currentPage = 2;
    	/**全部、已回复、未回复 ******/
		function clickReply(status){
			$("#consultStatus").val(status); //获取咨询的当前状态
			$.ajax({
				url : "${ctx}/consultComment/queryConsult.do",
				type : "post",
				data : {"status":status,"type":1},
				async : false,
				success : function(data, status) {
					var totalRecords = data.totalRecords; //获取总数
					var currentPageS = data.currentPage; //获取当前页数
					var resultList = data.resultList;  //获取返回的集合数据
					//移除已有的标签元素数据
					$(".myConsulting").empty();
					var optionHtml = optionByHtml(resultList);
					optionHtml += "<li class='pageRefresh' onclick='clickRefresh();'>点击刷新<img src='${ctx}/image/huan.png' alt='刷新' /></li> ";
					currentPage = 2;
					$(".myConsulting").append(optionHtml);
				},
				error : function(xhr, status, e) {
					alert("服务器请求错误，请检查！"+e)
				}
			});
		}
	
	/****咨询分页请求*****/
	function clickRefresh(){
		var consultStatus = $("#consultStatus").val();
		
		 // 加载菜单的数据
	    $.ajax({
	       	url : "${ctx}/consultComment/queryConsult.do",
			type : "post",
			data : {"status":consultStatus,"type":1,"currPage":currentPage},
	      	async : false,
	        success: function(data,status){
	        	currentPage =data.currentPage;
	        	currentPage++;
	         	var resultList = data.resultList;
	         	var totalRecords = data.totalRecords; //总条数
	        	if(resultList!=null && resultList.length>0){
        			var optionHtml = optionByHtml(resultList);
        			$(".pageRefresh").before(optionHtml);
	        	}else{
	        		$(".pageRefresh").text("数据加载完毕！！！")
	        		$(".pageRefresh").removeAttr("onclick");  //移除事件
	        	}	
	       	},
	        error: function(xhr, type){
	            alert('Ajax error!');
	        }
	    });
	}
	/***拼装html*****/
	function optionByHtml(resultList){
		var optionHtml = '';
		$.each(resultList, function(i,result){      
			var createTime = result.createTime;
			var createTimeStr="";
			if(createTime!=null){
				createTimeStr=timeStamp2String(createTime);
			}
			optionHtml+="<li> "
				+" <img src='${ctx}/image/pic184.png' alt='' class='evaluateGoodsI evaluateGoodsM'/> "
				+" <div class='evaluateGoodsW'> "
				+" 	<p>"+result.consultContent +"</p> "
				+" 	<time>"+createTimeStr+"</time> "
				if(result.status=='1'){
					optionHtml+=" <a href='${ctx}/consultComment/initMyconsultingData?id="+result.id+"'>已有回答</a> "
				}else{
					optionHtml+=" <a href='javascript:void(0);'><b>暂无回答</b></a> "
				}
				optionHtml+=" </div> "
					+" </li>" ;
		});
		return optionHtml;
	}
	
	
	 //格式化日期时间 
	function timeStamp2String(time){
	    var datetime = new Date();
	    datetime.setTime(time);
	    var year = datetime.getFullYear();
	    var month = datetime.getMonth() + 1 < 10 ? "0" + (datetime.getMonth() + 1) : datetime.getMonth() + 1;
	    var date = datetime.getDate() < 10 ? "0" + datetime.getDate() : datetime.getDate();
	    var hour = datetime.getHours()< 10 ? "0" + datetime.getHours() : datetime.getHours();
	    var minute = datetime.getMinutes()< 10 ? "0" + datetime.getMinutes() : datetime.getMinutes();
	    var second = datetime.getSeconds()< 10 ? "0" + datetime.getSeconds() : datetime.getSeconds();
	    return year + "-" + month + "-" + date+" "+hour+":"+minute+":"+second;
	}
	</script>
	
	
</head>
<body>
	<header>
			<nav class="headerTwo">
				<img src="${ctx}/image/bg.png" alt="" />
				<a href="javascript:history.back(-1)" class="fl"><img src="${ctx}/image/return.png" alt="" /></a>
				<h2>我的咨询</h2>
				<%@include file="../common/headerR.jsp"%> 
			</nav>
		</header>
		
	<input type="hidden" name="consultStatus" id="consultStatus" value="0">
	<ul class="evaluate myConsult clearfix sanWang">
			<li class='fl' onclick="clickReply('0');"><span>全部咨询</span></li>
			<li class='fl' onclick="clickReply('1');"><span>已回复</span></li>
			<li class='fl' onclick="clickReply('2');"><span>未回复</span></li>
	</ul>
		 <ul class="evaluateGoods myConsulting">
			<c:forEach items="${resultList}" var="result">
				<li>
					<img src="${ctx}/image/pic184.png" alt="" class="evaluateGoodsI evaluateGoodsM"/>
					<div class="evaluateGoodsW">
						<p>${result.consultContent }</p>
						<time><fmt:formatDate value="${result.createTime }" pattern="yyyy-MM-dd HH:mm:ss" /></time>
						<c:choose>
							<c:when test="${result.status=='1'}">
								<a href="${ctx}/consultComment/initMyconsultingData?id=${result.id}">已有回答</a>
							</c:when>
							<c:otherwise>
								<a href="javascript:void(0);"><b>暂无回答</b></a>
							</c:otherwise>
						</c:choose>
					</div>
				</li>
			</c:forEach>
			
			<li class="pageRefresh" onclick="clickRefresh();">点击刷新<img src="${ctx}/image/huan.png" alt="刷新" /></li>
			
			
		</ul> 
		<script type="text/javascript" src="${ctx}/js/public.js"></script>
</body>
</html>